package com.itheima.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;


//配置请求地址和资源的映射
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {

        // localhost:8080/backend/page/login/login.html
        //1. 添加映射
        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");

    }

   //扩展消息转化器

       @Override
       protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
          //1.构建消息转化器
           MappingJackson2HttpMessageConverter mc = new MappingJackson2HttpMessageConverter();

           //2.把我们自己转换功能添加到这个转化器里面 【相当于在包装一层】
           //2.1设置映射规则
           mc.setObjectMapper(new JacksonObjectMapper());

           converters.add(0,mc);

       }
}
